package net.oschina.zbus;

import java.util.HashMap;
import java.util.Map;

import org.zbus.client.Broker;
import org.zbus.client.Producer;
import org.zbus.client.broker.SingleBroker;
import org.zbus.client.broker.SingleBrokerConfig;
import org.zbus.remoting.Message;
import org.zbus.remoting.ticket.ResultCallback;

import com.alibaba.fastjson.JSON;

public class HttpCallbackClient {

	public static void main(String[] args) throws Exception { 
		SingleBrokerConfig config = new SingleBrokerConfig();
		config.setBrokerAddress("127.0.0.1:15555");
		Broker broker = new SingleBroker(config);
		
		Producer producer = new Producer(broker, "HttpCallback"); 
		
		Map<String, Object> body = new HashMap<String, Object>();
		body.put("assignee_id", 42);
		body.put("description", "issue内容");
		body.put("id", 532);
		body.put("issue_id", 0);
		body.put("labels", "enhancement,");
		body.put("milestone_id", 0);
		body.put("title", "issue标题");

		
		Request req = new Request();
		req.setDest_url("http://git.oschina.net/api/v3/projects/532/issues?private_token=sXMJZfzzZ8sbHLydwjAL");
		req.setToken_url("http://oschina.net/action/git_token/createIssue");
		req.setFail_retry(true);
		req.setRetry_count(5);
		req.setFail_log(true);
		req.setDest_body(JSON.toJSONString(body));
		
		Message msg = new Message();
		msg.setBody(JSON.toJSONBytes(req));
		
		producer.send(msg, new ResultCallback() {
			@Override
			public void onCompleted(Message result) {  
				System.out.println(result);
			}
		});
		
	}

}
